<?php

namespace app\admin\model\mental;

use think\Model;
use traits\model\SoftDelete;

class Testlog extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'mental_testlog';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'status_text'
    ];



    public function getStatusList()
    {
        return ['unfinishu' => __('Status unfinishu'), 'finish' => __('Status finish')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getContentAttr($value,$data){
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        if($data['type'] == 'component'){
            return json_decode($value,true);
        }
        return $value;
    }


    public function TestMain()
    {
        return $this->hasOne('TestMain', 'id', 'main_id')->bind(['main_title'=>'title']);
    }
}
